package main.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.orm.SugarRecord;
import com.whu.zj.MyApplication;
import com.whu.zj.R;
import com.whu.zj.UIHandler;


import chat.network.tcp.IMMessageReceiver;
import chat.network.tcp.PushControlReceiver;
import chat.network.tcp.PushService;
import model.OwnUser;
import weibo.acitivity.BokeActivity;

/**
 * 我的基本信息
 * Created by 凯 on 2015/11/12.
 */
public class MyActivity extends UIHandler.BaseActivity {
    // 返回按钮
    Button btn_back;
    // 头像
    ImageView img_avar;
    // 帐号信息
    TextView tv_account;
    // 真实姓名
    TextView tv_realName;
    // 退出
    View v_logout;
    // 博客
    View v_weibo;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        initview();
        initdata();
    }

    private void initdata() {
        OwnUser ownUser = MyApplication.getOwnUser();
        tv_account.setText(ownUser.getUser_ID()+"");
        tv_realName.setText(ownUser.getUser_RealName());
    }


    // 点击按钮
    View.OnClickListener itemClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v == v_logout) {
                // 杀死后台服务
                Intent intent = new Intent(MyActivity.this, PushControlReceiver.class);
                intent.putExtra(PushService.SERVICE_ACTION, PushService.ACTION_DESTORY);
                MyActivity.this.sendBroadcast(intent);

                // 退出所有界面
                UIHandler.uiHandler.finishiall();

                SugarRecord.deleteAll(OwnUser.class);
            } else if (v == btn_back) {
                finish();
            }
            else if (v == v_weibo)
            {
                Intent intent = new Intent(MyActivity.this, BokeActivity.class);
                MyActivity.this.startActivity(intent);
            }
        }
    };

    // 初始化view
    private void initview() {
        btn_back = (Button) findViewById(R.id.id_btn_back);
        btn_back.setOnClickListener(itemClick);
        tv_account = (TextView) findViewById(R.id.id_tv_account);
        tv_realName = (TextView) findViewById(R.id.id_tv_realName);

        v_logout = findViewById(R.id.id_v_logout);
        v_logout.setOnClickListener(itemClick);

        img_avar = (ImageView) findViewById(R.id.id_img_avar);
        v_weibo = findViewById(R.id.id_v_weibo);
        v_weibo.setOnClickListener(itemClick);
    }
}
